package com.lxw.study.behavioral.command.case3;

public class InsertTextCommand implements Command{
    private String textToInsert;
    private StringBuilder textEditor;
    private int position;

    public InsertTextCommand(String text, StringBuilder editor, int position) {
        this.textToInsert = text;
        this.textEditor = editor;
        this.position = position;
    }

    @Override
    public void execute() {
        textEditor.insert(position, textToInsert);
    }

    @Override
    public void undo() {
        textEditor.delete(position, position + textToInsert.length());
    }
}
